package Handler;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ServerOrderHandler extends IoHandlerAdapter {

	
	public final static Logger log = LoggerFactory.getLogger(ServerOrderHandler.class);
	
	@Override
	
	public void sessionCreated(IoSession session)
	{
		System.out.println("success!!!!");
	}
	
	
	@Override
	public void messageReceived(IoSession session,Object message) throws Exception
	{
		String str = message.toString();
		log.info("The message received is [" + str + "]");
		if(str.trim().equalsIgnoreCase("quit"))
		{
			System.out.println("Server Close!");
			session.close(true);
			return;
		}
		
		//sendMsgToClient(session);
	}
	
	
//	public void sendMsgToClient(IoSession session) throws IOException
//	{
//		BufferedReader bufred = new BufferedReader(new InputStreamReader(System.in));
//		String instring = bufred.readLine();
//		session.write(instring);
//		if(instring.equals("quit"));
//		{
//			
//			session.close(true);
//		}
	
	}
	
